<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Progma" content="no-cache" />
<link rel="stylesheet" href="<%=request.getContextPath()%>/css/mm_training.css" type="text/css" />
<link rel="stylesheet" href="<%=request.getContextPath()%>/css/user.css" type="text/css" />
<link type="text/css" href="<%=request.getContextPath() %>/css/smoothness/jquery-ui-1.7.1.custom.css" rel="stylesheet"/>
<script type="text/javascript" src="<%=request.getContextPath() %>/scripts/jquery/jquery-1.3.2.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/scripts/jquery/jquery-ui-1.7.1.custom.js"></script>
<script type="text/javascript">
	/**
	 *
	 * 刪除子帳戶 
	 *
	 */
	function deleteAccount(accountID) {
		if (!confirm('是否删除子帐户' + accountID + "?")) {
			return ;
		}
		var context = '<%=request.getContextPath()%>';
		// 請求開始時提示消息
		$("#loading").ajaxStart(function(){
			   $(this).dialog({
				   title:"正在刪除子帳戶,請稍等.......",
				   modal:true,
				   height:0,
				   resizable:false,
				   draggable:false
			   });
		});
		// 請求完成
		 $("#loading").ajaxComplete(function(request, settings){
			 $(this).dialog("destroy");
		});
		// 提交請求
		$.ajax({
			   url: context + "/setup/deleteSubAccount.do",
			   data: "accountname=" + accountID,
			   dataType:"html",
			   success: function (data) {
				   // 獲取返回消息 
				   var returnMessage = $("#returnMessage", data);
				   // 如果存在錯誤消息
				   if (returnMessage.length > 0) {
						var messageBox = $("<div></div>").html(returnMessage.text());
						messageBox.dialog({
							title:returnMessage.text(),
							resizable:false,
							draggable:false,
							buttons: {
								'關閉':function () {
									$(this).dialog("destroy");
								}
							},
							close: function (event, ui) {
								$(this).dialog("destroy");
							}
						});
						$("#" + accountID).remove();
				   } 
			   },
		   	   error: function (data) {
			   	   document.location.href = context + "/error.jsp?random=" + Math.random();
			   }
		});
	}

	/**
	 *
	 * 修改密码
	 *
	 *
	 */
	function updatePassword(accountID) {
		var context = '<%=request.getContextPath()%>';
		var iframe = document.createElement("iframe");
		$(iframe).attr("src",context + "/setup/goUpdateSubAccountPassword.do?accountname=" + accountID + "&random=" + Math.random());
		$(iframe).attr("frameborder",0);
		$(iframe).attr("marginheight",0);
		$(iframe).attr("marginwidth",0);
		$(iframe).attr("title","修改子账户密码");
		$(iframe).dialog({
			title:'修改子账户密码',
			resizable:false,
			draggable:false,
			width: 330,
			height: 200,
			buttons: {
				"关闭" : function () {
					$(this).dialog("destroy");
				},
				"修改" : function () {
					var newpass = $(this).contents().find("#newpass").val();
					var newpassagain = $(this).contents().find("#newpassagain").val();
					$(this).dialog("destroy");
					$.ajax({
						   url: context + "/setup/updateSubAccountPassword.do",
						   data: "accountname=" + accountID + "&newpass=" + newpass + "&newpassagain=" + newpassagain,
						   dataType:"html",
						   success: function (data) {
							   // 獲取返回消息 
							   var returnMessage = $("#returnMessage", data);
							   // 如果存在錯誤消息
							   if (returnMessage.length > 0) {
									var messageBox = $("<div></div>").html(returnMessage.text());
									messageBox.dialog({
										title:returnMessage.text(),
										resizable:false,
										draggable:false,
										buttons: {
											'關閉':function () {
												$(this).dialog("destroy");
											}
										},
										close: function (event, ui) {
											$(this).dialog("destroy");
										}
									});
							   } 
						   },
					   	   error: function (data) {
						   	   document.location.href = context + "/error.jsp?random=" + Math.random();
						   }
					});
				}
			}
		});
	}
</script>
<style type="text/css">
	.sidebarText {
	}
	.err_msg {
		color: red;
		font-size: 12px;
	}
	#individualForm td {
		font-size: 12px;
		white-space: nowrap;
	}
	body {
		font-size: 12px;
	}
</style>
<title>添加一個子帳戶</title>
</head>
<body bgcolor="#64748B">
<jsp:include page="/head.jsp"></jsp:include>
<td width="230" valign="top" bgcolor="#26354a" colspan="2"><br/>
	<table width="230" cellspacing="0" cellpadding="0" border="0">
		<tbody>
			<s:if test="('company'.equals(userType) && 'parentManager'.equals(managerLevel)) || 'company'.equals(person)">
				<tr>
					<td width="230" id="padding" class="sidebarText"><a href="<%=request.getContextPath()%>/setup/account.do">修改我的個人資料</a><br/>
					<br/></td>
				</tr>
				<tr>
					<td width="230" id="padding" class="sidebarText"><a href="<%=request.getContextPath()%>/setup/changeMobileAction.do">關聯手機號碼變更</a><br/>
					<br/></td>
				</tr>
			</s:if>
			<s:if test="'company'.equals(userType) && 'parentManager'.equals(managerLevel)">
				<tr>
					<td width="230" id="padding" class="sidebarText"><a href="<%=request.getContextPath()%>/setup/goSubAccount.do">增加一個管理帳號</a><br />
					<br />
					</td>
				</tr>
				<tr>
					<td width="230" id="padding" class="sidebarText"><a href="<%=request.getContextPath() %>/setup/subAccountManage.do">子帳號管理</a><br />
					<br />
					</td>
				</tr>
			</s:if>
			<s:if test="('company'.equals(userType) && 'parentManager'.equals(managerLevel)) || 'person'.equals(userType)">
				<tr>
					<td width="230" id="padding" class="sidebarText"><a href="<%=request.getContextPath()%>/setup/wallet.do">錢包設置</a><br/>
					<br/></td>
				</tr>
			</s:if>
		</tbody>
	</table>
	</td>
	<td valign="top" width='100%'>
		<form id="individualForm" action="<%=request.getContextPath() %>/setup/addSubAccount.do" method="post">
			<div style="border:1px solid #DADADA;min-width:700px;font-size: 12px;">
				<table width="60%" cellspacing="0" cellpadding="0" border="0">
					<tbody>
						<tr>
							<td width="15%" align="center">帳戶名
							</td>
							<td width="20%" align="left">是否可以查看報表
							</td>
							<td width="20%" align="left">是否可以購買廣告
							</td>
							<td width="20%" align="left">是否可以使用錢包
							</td>
							<td width="10%" align="center">刪除?
							</td>
							<td width="10%" align="center">修改密碼?
							</td>
						</tr>
						<s:iterator id="item" value="allSubAccounts">
							<tr id="<s:property value="userId"/>">
								<td width="15%" align="center"><s:property value="userId"/>
								</td>
								<td width="20%" align="left">
									<s:if test='"0".equals(formFunc)'>
										否
									</s:if>
									<s:else>
										是
									</s:else>
								</td>
								<td width="20%" align="left">
									<s:if test='"0".equals(advFunc)'>
										否
									</s:if>
									<s:else>
										是
									</s:else>
								</td>
								<td width="20%" align="left">
									<s:if test='"0".equals(BurseFunc)'>
										否
									</s:if>
									<s:else>
										是
									</s:else>
								</td>
								<td width="10%" align="center">
									<a onclick="deleteAccount('<s:property value="userId"/>');">刪除?</a>
								</td>
								<td width="10%" align="center">
									<a onclick="updatePassword('<s:property value="userId"/>');">修改?</a>
								</td>
							</tr>
						</s:iterator>
					</tbody>
				</table>
			</div>
		</form>
	</td>
	<div id="loading" style="color: red; display: none;">loading........</div>
<jsp:include page="/footer.jsp"></jsp:include>
</body>
</html>